<!--
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -->
<div class="container-fluid">
  <div ng-show='error'>
    <error></error>
  </div>

  <div ng-hide='error'>
    <breadcrumb></breadcrumb>

    <div class="content-box">
      <div class="row">
        <!-- begin finished update box -->
        <div ng-if="!inProgress" class="col-md-6 finished-update">

          <div class="text-center"><h3>Update Summary</h3></div>

          <div class="row">
            <div class="col-md-12 text-center">
              <span>started by <strong>{{update.update.summary.user}}</strong></span><br/>
              <span>final status <strong>{{update.update.summary.state.status | toNiceStatus}}</strong></span>
            </div>
          </div>

          <div class="row">
            <div class="col-md-3 col-md-offset-2">
              <time-display timestamp="update.update.summary.state.createdTimestampMs"></time-display>
            </div>
            <div class="col-md-2 time-divider">
              <span>~</span>
            </div>
            <div class="col-md-3">
              <time-display timestamp="update.update.summary.state.lastModifiedTimestampMs"></time-display>
            </div>
          </div>
          <div class="row">
            <div class="col-md-12">
              <div class="time-display-duration">
                 Duration: {{duration}}
              </div>
            </div>
          </div>

          <instance-summary
              instances="instanceSummary"
              stats="stats"
              size="instanceGridSize"
              status="update.update.summary.state.status">
          </instance-summary>
        </div>
        <!-- end finished update box -->

        <!-- begin update in progress box -->
        <div ng-if="inProgress" class="col-md-6 update-settings">

          <h3 ng-if="inProgress">Update Status</h3>

          <div class="progress-details">
          <span>started by <strong>{{update.update.summary.user}}</strong>, <span tooltip="{{update.update.summary.state.createdTimestampMs | toLocalTime}}">{{update.update.summary.state.createdTimestampMs | toElapsedTime}} ago</span></span><br/>
          <span>current status <strong>{{update.update.summary.state.status | toNiceStatus}}</strong></span>
          </div>

          <instance-summary instances="instanceSummary" stats="stats" size="instanceGridSize"></instance-summary>

        </div>
        <!-- end update in progress box -->

        <div class="col-md-6 update-settings">
          <h3>Update Settings</h3>

          <update-settings update="update"></update-settings>
        </div>
      </div>

      <hr/>

      <div class="row">
        <div class="col-md-6">
          <h4>Update Events</h4>
          <table class="table table-bordered table-striped">
            <thead>
              <tr>
                <th>event</th>
                <th>time</th>
                <th>user</th>
                <th>message</th>
              </tr>
            </thead>
            <tbody>
              <tr ng-repeat="e in update.updateEvents">
                <td>{{e.status | toNiceStatus}}</td>
                <td><span tooltip="{{e.timestampMs | toUtcTime}}">{{e.timestampMs | toElapsedTime }} ago</span></td>
                <td>{{e.user}}</td>
                <td>{{e.message}}</td>
              </tr>
            </tbody>
            <tfoot loading-footer ng-if="inProgress"></tfoot>
          </table>
        </div>

        <div class="col-md-6">
          <h4>Instance Events</h4>
          <table class="table table-bordered table-striped">
            <thead>
              <tr>
                <th>instance</th>
                <th>event</th>
                <th>time</th>
              </tr>
            </thead>
            <tbody>
              <tr ng-repeat="e in instanceEvents">
                <td><a href="/scheduler/{{role}}/{{environment}}/{{job}}/{{e.instanceId}}">{{e.instanceId}}</a></td>
                <td>{{e.action | toNiceAction}}</td>
                <td><span tooltip="{{e.timestampMs | toUtcTime}}">{{e.timestampMs | toElapsedTime}} ago</span></td>
              </tr>
            </tbody>
            <tfoot loading-footer ng-if="inProgress"></tfoot>
          </table>

          <pagination ng-change="changeInstancePage()" max-size="5" total-items="totalEvents" ng-model="currentPage" items-per-page="eventsPerPage"></pagination>
        </div>
      </div>
    </div>

    <div class="content-box">
      <div class="row">
        <div class="col-md-12">
          <h3>Job Configuration</h3>
          <pre>{{configJson}}</pre>
        </div>
      </div>
    </div>

  </div>
</div>
